<!--购物车-->
<template>
  <div class="cart-page">
    <!-- 空购物车的内容 -->
    <div class="emptycart" v-if="!showcart">
      <img src="https://x.dscmall.cn/static/dist/img/cart-empty.png" alt="" />
      <p>购物车空空,快去逛逛把</p>
      <button>去逛逛</button>
      <button>去看看</button>
    </div>

    <div class="cart-list" v-else>
      <div class="address">
        <span>江苏省 无锡市 滨湖区 蠡园街道</span>
      </div>
      <div class="cart-content">
        <ul class="cart-shop">
          <li v-for="cartListdata in cartListdatas" :key="cartListdata.shop_id">
            <!-- 店铺的信息 -->
            <div class="shop-name">
              <div class="shop-select">
                <!-- 选中的 -->
                <i
                  class="iconfont icon-yuanxingxuanzhongfill"
                  v-if="cartListdata.isShopSelect"
                ></i>
                <!-- 未选中的 -->
                <i class="iconfont icon-yuanxingweixuanzhong" v-else></i>
              </div>
              <h3>{{ cartListdata.shop_name }}</h3>
            </div>
            <!-- 所有商品的信息 -->
            <ul class="cart-goods-list">
              <li
                v-for="cartgoodsitem in cartListdata.children"
                :key="cartgoodsitem.goods_id"
              >
                <div class="goods-select">
                  <!-- 选中的 -->
                  <i
                    class="iconfont icon-yuanxingxuanzhongfill"
                    v-if="cartgoodsitem.isGoodsSelect"
                  ></i>
                  <!-- 未选中的 -->
                  <i class="iconfont icon-yuanxingweixuanzhong" v-else></i>
                </div>
                <div class="goods-content">
                  <img :src="cartgoodsitem.goods_pic" alt="" />
                  <div class="goods-info">
                    <div class="goods-title">
                      {{ cartgoodsitem.goods_name }}
                    </div>
                    <div class="goods-wrap">
                      <div class="goods-price">
                        ¥{{ cartgoodsitem.goods_price }}
                      </div>
                      <!-- 操作相关的内容 -->
                      <div class="addorminus">
                        <button
                          class="minus"
                          @click="buyNum > 1 ? buyNum-- : 1"
                        >
                          -
                        </button>
                        <input type="text" v-model="buyNum" class="numtext" />
                        <button class="add" @click="buyNum++">+</button>
                      </div>
                      <i class="iconfont icon-shoucang1"></i>
                      <i class="iconfont icon-shanchu1"></i>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
    <div class="cart-footer">
      <div class="select">
        <div class="selectall">
          <!-- 选中的 -->
          <i class="iconfont icon-yuanxingxuanzhongfill" v-if="isSelectAll"></i>
          <!-- 未选中的 -->
          <i class="iconfont icon-yuanxingweixuanzhong" v-else></i>
        </div>
        <span>全选</span>
      </div>
      <!-- 合计的内容 -->
      <div class="total">
        <span>合计:</span>
        <span class="total-price">¥6767676</span>
        <p>(以节省多少钱)</p>
      </div>
      <mt-button type="danger">去结算({{ buyNum }})</mt-button>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      showcart: true,
      cartListdatas: [
        {
          shop_id: 1,
          shop_name: "创新旗舰店",
          isShopSelect: false,
          children: [
            {
              goods_id: "1001",
              shop_id: 1,
              goods_name: "小米手机",
              goods_price: "1299.00",
              goods_pic:
                "https://x.dscmall.cn/storage/images/201809/thumb_img/0_thumb_G_1536614291475.jpg",
              buyNum: 1,
              isGoodsSelect: true,
            },
          ],
        },
        {
          shop_id: 0,
          shop_name: "商城自营",
          isShopSelect: false,
          children: [
            {
              goods_id: "1001",
              shop_id: 0,
              goods_name: "华为 HUAWEI Mate 30 麒麟990旗舰芯片4000万超感",
              goods_price: "1299.00",
              goods_pic:
                "https://x.dscmall.cn/storage/images/201809/thumb_img/0_thumb_G_1536614291475.jpg",
              buyNum: 1,
              isGoodsSelect: true,
            },
            {
              goods_id: "1002",
              shop_id: 0,
              goods_name: "2222222 30 麒麟990旗舰芯片4000万超感",
              goods_price: "1299.00",
              goods_pic:
                "https://x.dscmall.cn/storage/images/201809/thumb_img/0_thumb_G_1536614291475.jpg",
              buyNum: 1,
              isGoodsSelect: true,
            },
          ],
        },
      ],
      buyNum: 1,
      isSelectAll: true,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {},
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less">
.cart-page {
  i {
    font-size: 2rem;
  }
  .icon-yuanxingxuanzhongfill {
    color: rgb(242, 14, 40);
  }
  .emptycart {
    margin: 1.1rem;
    background-color: #fff;
    border-radius: 0.5rem;
    overflow: hidden;
    text-align: center;
    padding-bottom: 4rem;
  }
  .cart-list {
    .address {
      height: 5rem;
      line-height: 5rem;
      padding-left: 1rem;
    }
    .cart-content {
      .cart-shop {
        > li {
          width: calc(100% - 2rem);
          margin: 1rem;
          background: #fff;
          border-radius: 1rem;
          .shop-name {
            width: calc(100% - 2rem);
            margin: 0 1rem;
            height: 4.4rem;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            font-size: 1.4rem;
            margin-left: 1rem;
            // background: pink;
            h3 {
              margin-left: 2rem;
            }
          }
          .cart-goods-list {
            li {
              height: 8rem;
              width: calc(100% - 2rem);
              margin: 0rem 1rem;
              display: flex;
              align-items: center;
              .goods-content {
                display: flex;
                img {
                  width: 7rem;
                  height: 7rem;
                }
                .goods-info {
                  .goods-title {
                    width: 23.3rem;
                    height: 4rem;
                    line-height: 2rem;
                    font-size: 1.3rem;
                    //单行文本出现省略号
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                  }
                  .goods-wrap {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    height: 3rem;
                    // background: pink;
                    .goods-price {
                      font-size: 1.5rem;
                      color: rgb(242, 14, 40);
                      font-weight: 700;
                    }
                    .addorminus {
                      display: flex;
                      justify-content: space-between;
                      align-items: center;
                      padding: 1rem;
                      margin-left: 3rem;
                      button {
                        width: 2rem;
                        height: 2rem;
                        border-radius: 0 5px 5px 0;
                        background-color: #f2f3f5;
                      }
                      .minus {
                        border-radius: 5px 0 0 5px;
                      }
                      .add {
                        border-radius: 0 5px 5px 0;
                      }
                      input {
                        width: 2.5rem;
                        height: 2rem;
                        padding: 0;
                        font-size: 1.2rem;
                        border: 0;
                        margin: 1px;
                        background-color: #f2f3f5;
                        border-width: 1px 0;
                        color: #323233;
                        text-align: center;
                      }
                    }
                    i {
                      margin-right: 0.3rem;
                      color: #666;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  .cart-footer {
    width: calc(100% - 2rem);
    padding: 0 1rem;
    height: 4.4rem;
    position: fixed;
    bottom: 4.9rem;
    left: 0;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.4rem;
    .select {
      display: flex;
      .selectall {
        span {
          margin-left: 1rem;
        }
      }
    }

    .total {
      flex: 1;
      font-weight: 500;
      text-align: right;
      color: #333;
      padding-right: 1.2rem;
      .total-price {
        font-size: 1.8rem;
        font-weight: 700;
        color: rgb(242, 14, 40);
        margin-left: 1.2rem;
      }
      p {
        font-size: 1.2rem;
        color: #999;
      }
    }
  }
}
</style>